

***************
*** Table 5 ***
***************

clear all

*Set the folder where data are
cd ""


use B2_correct,clear

*drop HH and workers observed only once
drop if honeobsfyr==1
drop if wnyrsp==1

bysort dhcode year: gen counter = _n == 1   // create a dummy variable 1 for first HH obs in a year, 0 otherwise
by dhcode: replace counter = sum(counter)     // sum the 1s and 0s only within HH, hence the first year that first member in HH is observed is 1, the second year is 2 etc
by dhcode: egen hhnyrsp = max(counter)     //  within HH replaces all values with the highest to give the HH number of years in the UHS
label var hhnyrsp "HH total number of years in UHS panel"
tab hhnyrsp 
drop if hhnyrsp==1

xtset dhcode year

*** county specific trends
quiet tab countyid, gen(countytrend)
quiet for num 1/658: replace countytrendX=countytrendX*year

*** city specific trends
quiet tab cityid, gen(citytrend)
quiet for num 1/194: replace citytrendX=citytrendX*year
replace citygovbalgdp=. if citygovbalgdp<-20
gen lncitygovexp=ln(citygovexp)

** tabulate industries because xtivreg2 does not take factor variables
set more off
tab industryH, gen(indH)
tab industryS, gen(indS)
tab occupationH, gen(occH)
tab occupationS, gen(occS)
tab maritstatusH, gen(marH)
tab maritstatusS, gen(marS)
tab educH, gen(edH)
tab educS, gen(edS)
tab educ2H, gen(ed2H)
tab educ2S, gen(ed2S)


*** gen provinceXtime FE since xtivreg does not use factor variables
set more off
egen provxyr = group(provid year)
tab provxyr, gen(pxy)
egen cityxyr = group(cityid year)
tab cityxyr, gen(cxy)

drop if hMWshare==.


*Controls
global xhhiv familysize houseown genderH genderS ageH ageS age2H age2S wexperH wexperS wexper2H wexper2S migrH migrS migr2H migr2S hhrealotherincUHS hhrealhsln

global xhhiv1 familysize genderH genderS ageH ageS age2H age2S wexperH wexperS wexper2H wexper2S migrH migrS migr2H migr2S hhrealotherincUHS hhrealhsln

*City
global xcity lnrealcitygdp lnrealcitysalary cityunemplrate citypop       



*Liquidity Constraints

*income from property
gen propertyinc= d923>0 if !missing(d923)
sum d923 if hMWshare>0 & propertyinc==1, detail
gen propertyincmed = d923>630 if !missing(d923)
gen effrmwpropmed=effrealmw*propertyincmed
gen hhrlipropmed=hhreallabinc*propertyincmed

*interest, dividend and insurance income
gen idiincome=d9231+d9232+d9233
gen idiincdum=1 if idiincome>0 & !missing(idiincome)
replace idiincdum=0 if idiincdum==.
gen hhrliidiinc=hhreallabinc*idiincdum
gen effrmwidiinc=effrealmw*idiincdum

*outright house owner
gen nethown=1 if houseown==1 & mortgage==0 & houseown!=.
replace nethown=0 if nethown==. & houseown!=.
gen hhrlinethown=hhreallabinc*nethown
gen effrmwnethown=effrealmw*nethown



*drop 2002 for mechancial correlation
drop if year==2002


*Table 5

est clear 
set more off
xtivreg2 hhrealcons (hhreallabinc hhrlipropmed = effrealmw effrmwpropmed)  $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare==0, fe robust cluster(countyid)
est sto m1

xtivreg2 hhrealcons (hhreallabinc hhrlipropmed = effrealmw effrmwpropmed) propertyincmed $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.5, fe robust cluster(countyid)
est sto m2

xtivreg2 hhrealcons (hhreallabinc hhrlipropmed = effrealmw effrmwpropmed) propertyincmed $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.75,  fe robust cluster(countyid)
est sto m3

xtivreg2 hhrealcons (hhreallabinc hhrliidiinc = effrealmw effrmwidiinc)  $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare==0, fe robust cluster(countyid)
est sto m4

xtivreg2 hhrealcons (hhreallabinc hhrliidiinc = effrealmw effrmwidiinc) idiincdum $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.5, fe robust cluster(countyid)
est sto m5

xtivreg2 hhrealcons (hhreallabinc hhrliidiinc = effrealmw effrmwidiinc) idiincdum $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.75, fe robust cluster(countyid)
est sto m6

xtivreg2 hhrealcons (hhreallabinc hhrlinethown = effrealmw effrmwnethown) nethown $xhhiv1 $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare==0, fe robust cluster(countyid)
est sto m7

xtivreg2 hhrealcons (hhreallabinc hhrlinethown = effrealmw effrmwnethown) nethown $xhhiv1 $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.5, fe robust cluster(countyid)
est sto m8

xtivreg2 hhrealcons (hhreallabinc hhrlinethown = effrealmw effrmwnethown) nethown $xhhiv1 $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.75,  fe robust cluster(countyid)
est sto m9

estout m1 m2 m3 m4 m5 m6 m7 m8 m9  using "Table_5.tex", style(tex) cells(b(fmt(3)) se(star par fmt(3))) delim("&") numbers starlevels(* 0.10 ** 0.05 *** 0.01) ///
collabels( , none) mlabels( "$ S=0 $" "$ S>0.5 $" "$ S>0.75 $" "$ S=0 $" "$ S>0.5 $" "$ S>0.75 $" "$ S=0 $" "$ S>0.5 $" "$ S>0.75 $") ///
mgroups(, lhs(Dep.var.: Household Consumption) pattern(1 0 0 1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
stats(N N_clust N_g  idp, fmt(0 0 0 3 3) label("Observations"  "N clusters" "N households" "Irrelevant instr. (pval)")) ///
keep(hhreallabinc hhrlipropmed hhrliidiinc hhrlinethown) varlabels(hhreallabinc "Household labor income" hhrlipropmed "Household labor income\\ $\times$ property dum. " ///
hhrlidepmed "Household labor income \\ $\times$ capital income dum." hhrlinethown "Household labor income \\ $\times$ house ownership dum. ") varwidth(20) modelwidth(10) ///
prehead("\begin{table}[tbhp] \centering \resizebox{\textwidth}{!} { \begin{tabular}{l*{9}{c}}" \toprule) posthead(\cmidrule(rl){2-4}\cmidrule(rl){5-7}\cmidrule(rl){8-10} \\)  ///
prefoot( \\ HH member controls & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\ HH-level controls & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes \\ City-level controls & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\ Household FE & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes \\  Prov $\times$ year FE & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\ County Trend & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\ ) postfoot( \bottomrule "\end{tabular} } \end{table} ") replace



